package common

import "reflect"

// 将结构体数组转换为指定字段的数组
func StructsToFields[arr interface{}, r interface{}](codeLine *[]arr, toArrayField string) []r {
	var codeLine1 []r
	for i := range *codeLine {
		ok := reflect.ValueOf(codeLine).Elem().Index(i).FieldByName(toArrayField)
		if ok.IsValid() {
			codeLine1 = append(codeLine1, ok.Interface().(r))
		}
	}
	return codeLine1
}
